package SwingThread;
import java.awt.EventQueue;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.SwingUtilities;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Demo {

	private JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Demo window = new Demo();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Demo() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);

		JButton btnNewButton = new JButton("点击");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SwingDemo fg = new SwingDemo();
				fg.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				fg.setSize(300, 100);
				fg.setVisible(true);
				DemoThread1 d = new DemoThread1();
				Thread t = new Thread(d);
				t.start();
			}
		});
		btnNewButton.setBounds(160, 114, 127, 44);
		frame.getContentPane().add(btnNewButton);
	}
}

class DemoThread1 implements Runnable {
	public void run() {
		try {
			for (int i = 0; i < 10; i++) {
				Thread.sleep(2000);
				System.out.println("开始线程" + i);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}